/*
 * @Author: 0x9DEFA478
 * @Date: 2025-10-03 22:12:25
 * @LastEditTime: 2025-10-04 19:29:09
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * 
 */
#ifndef hSystemAPI_Windows_IO_Overlapped_HPP_
#define hSystemAPI_Windows_IO_Overlapped_HPP_
#if defined(_WIN32)
#include "./Handle.hpp"
#endif


namespace SystemAPI{

  namespace Windows{

#if defined(_WIN32)
    class IO_Overlapped{
      public:
        IO_Overlapped();
        IO_Overlapped(Handle&& handle);
        ~IO_Overlapped()noexcept;

        IO_Overlapped(const IO_Overlapped&)=delete;
        IO_Overlapped(IO_Overlapped&& io_overlapped)noexcept;
        
        IO_Overlapped& operator=(const IO_Overlapped&)=delete;
        IO_Overlapped& operator=(IO_Overlapped&& io_overlapped)noexcept;

        HANDLE GetHandle()const noexcept{return handle.GetHandle();}

        void ReadFile(void* Buffer,int BufferSize);
        //返回 -2:被终止 -1:超时 0:连接断开 大于0:读取到的数据长度 异常:错误信息
        int WaitRead(int Timeout);
        void CancelRead();

        void WriteFile(const void* Data,int DataLength);
        //返回 -2:被终止 -1:超时 0:连接断开 大于0:写入的数据长度 异常:错误信息
        int WaitWrite(int Timeout);
        void CancelWrite();

      private:
        void* privateData;
        Handle handle;
    };
#endif

  }

}


#endif //hSystemAPI_Windows_IO_Overlapped_HPP_
